<template>
    <view class="subject">
        <view v-if="!showEvery" class="crosswise">
            <scroll-view scroll-x="true" show-scrollbar="false" class="srcoll_box">
                <view class="filter_list">
                    <view
                        v-for="(item, index) in tabsList"
                        :key="index"
                        :class="{ filter_list_item: true, active: xzIndex === index }"
                        @click="selectFun(item, index)"
                    >
                        <text class="text">{{ item.gradeName }}</text>
                    </view>
                </view>
            </scroll-view>
            <image :src="arrow" mode="" class="arrows_icon" @click="tapShowEvery"></image>
        </view>
        <view v-else class="full_display">
            <view class="filter_list full">
                <view
                    v-for="(item, index) in tabsList"
                    :key="index"
                    :class="{ filter_list_item: true, active: xzIndex === index }"
                    @click="selectFun(item, index)"
                >
                    <text class="text">{{ item.gradeName }}</text>
                </view>
            </view>
            <image
                :src="arrow"
                mode=""
                :class="{ arrows_icon: true, arrows_up: showEvery }"
                @click="tapShowEvery"
            ></image>
        </view>
    </view>
</template>

<script setup>
import { ref } from 'vue';
const props = defineProps({
    tabsList: Array,
});
const emits = defineEmits(['handleFilter']);
const OSS_URL = import.meta.env.VITE_OSS_HOST;
const arrow = `${OSS_URL}/iconfont/dark_arrow.png`;
const checkedBg = `url(${OSS_URL}/urm/checked_bg.png)`;
const xzIndex = ref(0);
const showEvery = ref(false);

function selectFun(e, i) {
    xzIndex.value = i;
    emits('handleFilter', e);
}

function tapShowEvery() {
    showEvery.value = !showEvery.value;
}
</script>

<style lang="scss" scoped>
.subject {
    ::-webkit-scrollbar {
        width: 0;
        height: 0;
        color: transparent;
        display: none;
    }

    .arrows_icon {
        margin: 16rpx 0 0 0;
        width: 32rpx;
        height: 32rpx;
        transform: rotate(180deg);
    }
}

.crosswise {
    display: flex;
    justify-content: space-between;

    .srcoll_box {
        width: calc(100% - 48rpx);
    }
}

.filter_list {
    display: flex;
    flex-direction: row;
    padding-bottom: 13rpx;

    &_item {
        position: relative;
        padding: 12upx 32upx;
        height: 66rpx;
        background-color: #f9f9fb;
        margin-right: 16upx;
        font-size: 30rpx;
        line-height: 42rpx;
        font-weight: 500;
        border-radius: 8upx;
        box-sizing: border-box;

        .text {
            max-width: 300rpx;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .item-icon {
            position: absolute;
            bottom: -13rpx;
            left: 50%;
            transform: translateX(-50%);
            width: 35upx;
            height: 20upx;
        }
    }
}

.full_display {
    position: relative;
    .full {
        flex-wrap: wrap;
        .filter_list_item:nth-child(5n) {
            margin-right: 0;
        }

        .filter_list_item:nth-child(n + 6) {
            margin-top: 28rpx;
        }
    }

    .arrows_up {
        position: absolute;
        right: 0;
        bottom: 30rpx;
        transform: rotate(0deg);
    }
}

.active {
    height: 82rpx;
    background-image: v-bind(checkedBg);
    background-size: 100%;
    background-repeat: no-repeat;
    color: #fff;
    background-color: transparent;
}
</style>
